<?php
namespace app\admin\controller;

use app\admin\model\AdminLoginLog;
use app\admin\model\AdminNode;
use think\Controller;

class Index extends Controller
{

    protected $middleware = [
        "CheckPermission",
        "Log",
    ];

    protected $loginLogModel;
    private $adminInfo = null;
    private $nodeModel;
    public function initialize()
    {
        parent::initialize();
        $this->loginLogModel = new AdminLoginLog();
        $this->adminInfo = session('user');
        $this->nodeModel = new AdminNode();
    }

    public function index()
    {

        if($this->adminInfo == null) return redirect(url('/admin/pub/login'));

        $role_id = $this->adminInfo['role_id'];

        $myNodes = $this->nodeModel->getNodesByRoleId($role_id);

        return $this->view->fetch('index',['myNodes'=>$myNodes]);
    }

    public function welcome(){

        $logInfo = $this->loginLogModel->getLastLog($this->adminInfo['admin_id']);

        return $this->view->fetch('welcome',['lastLog'=>$logInfo]);
    }





}
